package demo4_9;

import java.util.Arrays;

public class Test {
    //采用冒泡排序
    public static void mySort(Comparable[] comparables) {
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if (comparables[j].compareTo(comparables[j + 1]) > 0) {
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j + 1];
                    comparables[j + 1] = tmp;
                }
            }
        }

    }

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan", 10);
        students[1] = new Student("lisi", 15);
        students[2] = new Student("wangwu", 18);

        mySort(students);
        System.out.println(Arrays.toString(students));
    }
}
